﻿@model Epi.Web.MVC.Models.FormModel
@{
    ViewBag.Title = "Epi Info™ Cloud Data Capture - Home";// + " - "+ 
	// Model.SurveyName + " - " + Model.IsDraftModeStyleClass;
	Layout = "~/Views/Shared/_Layout.cshtml";
	
}
@*<script type="text/javascript" >

	  $(document).ready(function () {
		  // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!




		  $("#VideoDialog").dialog({
			  autoOpen: false,
			  show: "blind",
			  hide: "blind",
			  resizable: false,
			  height: 410,
			  width: 500,
			  modal: true
		  });

	  });

</script>*@


<script type="text/jscript">



    $(function () {

        $("#exitdialog").dialog({
            autoOpen: false,
            show: "blind",
            hide: "blind",
            resizable: false,
            height: 150,
            width: 420,
            modal: true,
            buttons: [{

                "text": 'Yes',
                "click": function () {
                    $.ajax({

                        //    url: 'Home/Delete/'+ $("#exitdialog").data('ResponseId') + '/' + '@ViewBag.UserId',
                        url: '@Url.Action("Delete","Home")' + '?ResponseId=' + $("#exitdialog").data('ResponseId'),
                        type: 'POST',
                        cache: false,
                        contentType: 'application/json; charset=utf-8',
                        success: successFunc,
                        error: errorFunc
                    });

                    //                    $.ajaxSetup({ cache: false });

                    function successFunc(data, status) {
                        $("#exitdialog").dialog("close");
                        ReadResponses($('#hidFormId').val(), $('#hidPageNumber').val(), '', '');
                    }

                    function errorFunc() {
                        alert('error');
                    }

                },
                "class": 'dialogbtn'

            }, {
                "text": 'No',
                "click": function () {
                    $(this).dialog("close");
                },
                "class": 'dialogbtn'

            }]

        });


        $(document).on("click", "button[name='DeleteButton']", function (e) {
            e.preventDefault();
            
            var ResponseId = $(this).attr("value");
            var SessionTimeOut = $('#SYSTEM_SESSION_TIMEOUT_HIDDEN').val() * 60000;

            $("#ConcurrencyMessage").show();
            $(".dialogbtn").show();
            $("#NotifyMessage").hide();

            var ActionUrl = '@Url.Action("CheckForConcurrency", "Home")' + '?responseid=' + this.id;
            $.ajax({
                url: ActionUrl,
                type: 'POST',
                cache: false,
                contentType: 'application/json; charset=utf-8',
                //data: JSON.stringify(model),
                success: successFunc,
                Error: errorFunc
            });
            //		 $.ajaxSetup({ cache: false });

            function successFunc(data, status) {
                var loggedInUserId = data.LoggedInUserId
                var UpdatedDate = data.DateUpdated;
                UpdatedDate = UpdatedDate.replace(/[^0-9 +]/g, '');
                UpdatedDate = new Date(parseInt(UpdatedDate));

                var EditingDuration = Math.abs(new Date() - UpdatedDate);


                if (data.Status == 2 || data.Status == 4 || data.Status == 3) {


                    $("#exitdialog").data('ResponseId', ResponseId)
                    $("#exitdialog").dialog("open");

                } else {
                    // if time elapsed is less the   system timeout
                    if (EditingDuration <= SessionTimeOut && loggedInUserId != data.LastActiveUserId) {
                           alert("This record is being edited by another user.");
                        }
                   else
                        {
                        UnLockRecordForDelete(ResponseId);
                

                        }






                    //$("#ConcurrencyDialog").data('ResponseId', ResponseId)
                    //$("#LastUpdated").val(UpdatedDate);
                    //$("#EditingDuration").val(  msToTime(EditingDuration));
                    //$("#ConcurrencyDialog").dialog("open");
                }
            }

            function errorFunc() {
                alert('error');
           }


    });



        $("button[class*='metro-tile']").click(function (e) {
            ShowSppiner();
           
        $("#dropdown-2").val( $("#FORM_SelectedOrgId_HIDDEN").val());
        e.preventDefault();
        if ('@Model.SelectedForm' == "") {
                $("button[class*='metro-tile']").removeClass('metro-set');
                SetSettingButtonValue($(this).attr('data-FormId'));
                $(this).addClass('metro-set');
                ResetSearchFields();
                ReadResponses($(this).attr('data-FormId'), 1, '', '');
                // alert(1);
            }
            else {
                if ($("#FORM_SELECTED_HIDDEN").val() == "") {
                    $("button[class*='metro-tile']").removeClass('metro-set');
                    SetSettingButtonValue('@Model.SelectedForm');
                    $('#' + '@Model.SelectedForm').addClass('metro-set');
                    $("#FORM_SELECTED_HIDDEN").val('@Model.SelectedForm');
                    ReadResponses('@Model.SelectedForm', '@Session["PageNumber"]', '', '');
                    // alert(2);
                    //test
                }
                else {

                    $("button[class*='metro-tile']").removeClass('metro-set');
                    SetSettingButtonValue($(this).attr('data-FormId'));
                    $(this).addClass('metro-set');
                    //  $("#FORM_SELECTED_HIDDEN").val('');
                    ResetSearchFields();
                    ReadResponses($(this).attr('data-FormId'), 1, '', '');
                    //alert(3);
                }

            }
            $("#right").show();
            //alert('1');
            //            $.ajax({
            //                url: '@Url.Action("ReadResponseInfo","Home")' + '?formid=' + $(this).attr('data-FormId'),
            //                type: 'GET',
            //                contentType: 'application/json; charset=utf-8',
            //                //data: JSON.stringify(model),
            //                success: successFunc,
            //                error: errorFunc
            //            });
            //            $.ajaxSetup({ cache: false });

            //            function successFunc(data, status) {
            //                $('#right').html(data);
            //            }

            //            function errorFunc() {
            //                alert('error');
            //            }

            //            ReadResponses($(this).attr('data-FormId'), 1, '', '');
            //return page to the top when a form is selected if the list of forms is too long.

            $("html, body").animate({ scrollTop: 0 }, "slow");
           // CloseSppiner()
            return false;
        });



        $(document).on("click", "button[name='Search']", function (e) {
            e.preventDefault();
            $("#right").show();
            var formid = $('#hidFormId').val();
            var pageNumber = $('#hidPageNumber').val();
            //            Sort = 'ASC';
            //            SortField = $("#columns").val(); // 'PetsName';
            var Sort = $("#FORM_SORTORDER_HIDDEN").val();
            var SortField = $("#FORM_SORTFIELD_HIDDEN").val();
            ReadResponses(formid, 1, Sort, SortField);

            //            $.ajax({
            //                url: '@Url.Action("ReadSortedResponseInfo","Home")' + '?formid=' + formid + "&page=1&sort=" + Sort + "&sortfield=" + SortField
            //                + ReadSearchFields() ,
            //                type: 'GET',
            //                contentType: 'application/json; charset=utf-8',
            //                //data: JSON.stringify(model),
            //                success: successFunc,
            //                error: errorFunc
            //            });
            //            $.ajaxSetup({ cache: false });

            //            function successFunc(data, status) {
            //                $('#right').html(data);
            //            }

            //            function errorFunc() {
            //                alert('error');
            //            }

        });

        $(document).on("click", "button[name='ResetSearch']", function (e) {
            // alert(1);
            e.preventDefault();
            $("#right").show();
            var formid = $('#hidFormId').val();
            var pageNumber = $('#hidPageNumber').val();
            var Sort = ''; // $("#FORM_SORTORDER_HIDDEN").val();
            var SortField = ''; //$("#FORM_SORTFIELD_HIDDEN").val();
            var OrgId = $("#dropdown-2").val();
            var col1 = '';
            var val1 = '';
            var col2 = '';
            var val2 = '';
            var col3 = '';
            var val3 = '';
            var col4 = '';
            var val4 = '';
            var col5 = '';
            var val5 = '';

            $.ajax({
                url: '@Url.Action("ReadSortedResponseInfo","Home")' + '?formid=' + formid + "&page=1&sort=" + Sort + "&sortfield=" + SortField + "&orgid=" + OrgId
                + "&col1=" + col1 + "&val1=" + val1 + "&col2=" + col2 + "&val2=" + val2 + "&col3=" + col3 + "&val3=" + val3 + "&col4=" + col4 + "&val4=" + val4 + "&col5=" + col5 + "&val5=" + val5,
                cache: false,
                type: 'GET',
                contentType: 'application/json; charset=utf-8',
                //data: JSON.stringify(model),
                success: successFunc,
                error: errorFunc
            });
            //            $.ajaxSetup({ cache: false });

            function successFunc(data, status) {
                $('#right').html(data);
            }

            function errorFunc() {
                alert('error');
            }

        });

        //Sort by Logic for ASC and DESC button clicks
        $(document).on("click", "button[id='ResetSort']", function (e) {
            
            e.preventDefault();
            $("#right").show();
            var formid = $('#hidFormId').val();
            var pageNumber = $('#hidPageNumber').val();
            var Sort = '';
            var SortField = ''; // 'PetsName';
            $("#FORM_SORTORDER_HIDDEN").val(Sort);
            $("#FORM_SORTFIELD_HIDDEN").val(SortField);
            ReadResponses(formid, 1, Sort, SortField,true);

        });
        $(document).on("click", "button[id='SortASC']", function (e) {
            e.preventDefault();
            $("#right").show();
            var formid = $('#hidFormId').val();
            var pageNumber = $('#hidPageNumber').val();
            var Sort = 'ASC';
            var SortField = $("#columns").val(); // 'PetsName';
            $("#FORM_SORTORDER_HIDDEN").val(Sort);
            $("#FORM_SORTFIELD_HIDDEN").val(SortField);
            ReadResponses(formid, 1, Sort, SortField);

            //            $.ajax({
            //                url: '@Url.Action("ReadSortedResponseInfo","Home")' + '?formid=' + formid + "&page=1&sort=" + Sort + "&sortfield=" + SortField + ReadSearchFields(),
            //                type: 'GET',
            //                contentType: 'application/json; charset=utf-8',
            //                //data: JSON.stringify(model),
            //                success: successFunc,
            //                error: errorFunc
            //            });
            //            $.ajaxSetup({ cache: false });

            //            function successFunc(data, status) {
            //                $('#right').html(data);
            //            }

            //            function errorFunc() {
            //                alert('error');
            //            }

        });

        $(document).on("click", "button[id='SortDESC']", function (e) {
            e.preventDefault();
            $("#right").show();
            var formid = $('#hidFormId').val();
            var pageNumber = $('#hidPageNumber').val();
            var Sort = 'DESC';
            var SortField = $("#columns").val(); // 'PetsName';
            $("#FORM_SORTORDER_HIDDEN").val(Sort);
            $("#FORM_SORTFIELD_HIDDEN").val(SortField);
            ReadResponses(formid, 1, Sort, SortField);

            //            $.ajax({
            //                url: '@Url.Action("ReadSortedResponseInfo","Home")' + '?formid=' + formid + "&page=1&sort=" + Sort + "&sortfield=" + SortField + ReadSearchFields(),
            //                type: 'GET',
            //                contentType: 'application/json; charset=utf-8',
            //                //data: JSON.stringify(model),
            //                success: successFunc,
            //                error: errorFunc
            //            });
            //            $.ajaxSetup({ cache: false });

            //            function successFunc(data, status) {
            //                $('#right').html(data);
            //            }

            //            function errorFunc() {
            //                alert('error');
            //            }

        });


        /////////////////////




        //////////////////////
        $(document).on("click", "a[name='lnkPager']", function (e) {
            e.preventDefault();

            var sortOrder = $(this).attr('data-sort');
            var sortField = $(this).attr('data-sortfield');

            if (sortOrder == undefined) {
                sortOrder = '';
            }

            if (sortField == undefined) {
                sortField = '';
            }

            ReadResponses($(this).attr('data-formid'), $(this).attr('data-pagenumber'), sortOrder, sortField);

        });




        $("#dropdown-1").change(function () {

            var OrgId = $("#dropdown-2").val();

            FilterRecords(this, OrgId);
            //FilterRecordsByOrg(OrgId);
            $("#right").hide();
            $("button[class*='metro-tile']").removeClass('metro-set');

            $("button:visible").triggerHandler('click');


        });

        $("#dropdown-2").change(function () {

            var src = $(this).val();
            //alert(src);
            var orgId = $("#dropdown-2").val();
            $("#FORM_SelectedOrgId_HIDDEN").val(orgId);
            FilterRecordsByOrg(src);
            $("#dropdown-1").val('3');
        });

        //  $("button:visible").triggerHandler('click');

    });
    //ConcurrencyDialog
    $(function () {



        $("#ConcurrencyDialog").dialog({
            autoOpen: false,
            show: "blind",
            hide: "blind",
            resizable: false,
            height: 300,
            width: 500,
            modal: true,
            buttons: [{

                "text": 'Notify',
                "click":function () {
                    var ActionUrl = '@Url.Action("Notify", "Home")' + '?responseid=' + $("#ConcurrencyDialog").data('ResponseId');
                    $.ajax({
                        url: ActionUrl,
                        type: 'POST',
                        dataType: "json",
                        //cache: false,
                        async: false,
                        contentType: 'application/json; charset=utf-8',
                        //data: JSON.stringify(model),
                        success: successFunc,
                        Error: errorFunc
                    });
                    //		 $.ajaxSetup({ cache: false });

                    function successFunc(data, status) {
                        // $("#ConcurrencyDialog").dialog("close");
                        $("#ConcurrencyMessage").hide();
                        $(".dialogbtn").hide();

                        $("#NotifyMessage").show();

                    }

                        function errorFunc() {
                            alert('error');
                        }

                },
                "class": 'dialogbtn'

            }, {
                "text": 'Cancel',
                "click": function () {
                    $(this).dialog("close");
                },
                "class": 'dialogbtn'

            }]

        })
    });


    $(document).ready(function () {
        // e.preventDefault();
        //$(this).addClass('metro-set');
        var ActionUrl = "";
        var Url = window.location.pathname;
        var ResultUrl = "";
        if (Url.indexOf("/") != -1)
            ResultUrl = Url.substring(Url.lastIndexOf("/") + 1);
        else
            ResultUrl = Url;

        var FieldId = "#" + ResultUrl

        if (ResultUrl.toUpperCase() != "HOME" && ResultUrl.toUpperCase() != "INDEX") {

            $("button[class*='metro-tile']").removeClass('metro-set');
            $(FieldId).addClass('metro-set');
            //ActionUrl = '@Url.Action("ReadSortedResponseInfo","Home")' + "?formid=" + ResultUrl + "&page=1";
            //            ReadResponse(ActionUrl);
            //ReadResponses(ResultUrl, 1, '', '');
            var OrgId = '@Session["SelectedOrgId"]';
            $("#FORM_SelectedOrgId_HIDDEN").val(OrgId);
            FilterRecordsByOrg(OrgId);
        }
        else {

            //  $("button:visible").triggerHandler('click');
            var OrgId1 = $("#dropdown-2").val();
            $("#FORM_SelectedOrgId_HIDDEN").val(OrgId1);
            FilterRecordsByOrg(OrgId1);

        }
        //Use of Organization filter




        $("#right").show();

        // setup the dialog
        $("#TimeOutdialog").dialog({
            autoOpen: false,
            modal: true,
            width: 400,
            height: 160,
            closeOnEscape: false,
            draggable: false,
            resizable: false,
            /* buttons: {
            'Continue Session': function () {
            $(this).dialog('close');
            }
            }*/

            buttons: [{
                "text": 'Continue Session',
                "click": function () {
                    $(this).dialog('close');
                    
                },
                "class": 'dialogbtn'
            }]


        });
        // cache a reference to the countdown element so we don't have to query the DOM for it on each ping.
        var $countdown = $("#dialog-countdown");

        // start the idle timer plugin
        $.idleTimeout('#TimeOutdialog', 'div.ui-dialog-buttonpane button:first', {
           // idleAfter:  840 ,// 900,
            //pollingInterval: 2,
            keepAliveURL: 'keepalive.php',
            //serverResponseEquals: 'OK',
            onTimeout: function () {
                //window.location = "timeout.htm";
                window.location = '@Url.Action("Index","Login")';
                //'/Login';

                //GetRedirectionUrl() + '/1';
                //'~/Login/Index';
                 

            },
            onIdle: function () {
                $(this).dialog("open");
                
            },
            onCountdown: function (counter) {
                $countdown.html(counter); // update the counter
            }
        });

    });
    
    function ReadSearchFields() {
        var col1 = $("#SearchModel_SearchCol1").val();
        var val1 = $("#SearchModel_Value1").val();
        var col2 = $("#SearchModel_SearchCol2").val();
        var val2 = $("#SearchModel_Value2").val();
        var col3 = $("#SearchModel_SearchCol3").val();
        var val3 = $("#SearchModel_Value3").val();
        var col4 = $("#SearchModel_SearchCol4").val();
        var val4 = $("#SearchModel_Value4").val();
        var col5 = $("#SearchModel_SearchCol5").val();
        var val5 = $("#SearchModel_Value5").val();
        return "&col1=" + col1 + "&val1=" + val1 + "&col2=" + col2 + "&val2=" + val2 + "&col3=" + col3 + "&val3=" + val3 + "&col4=" + col4 + "&val4=" + val4 + "&col5=" + col5 + "&val5=" + val5;
    }

    function ResetSearchFields() {
        $("#SearchModel_SearchCol1").val('');
        $("#SearchModel_Value1").val('');
        $("#SearchModel_SearchCol2").val('');
        $("#SearchModel_Value2").val('');
        $("#SearchModel_SearchCol3").val('');
        $("#SearchModel_Value3").val('');
        $("#SearchModel_SearchCol4").val('');
        $("#SearchModel_Value4").val('');
        $("#SearchModel_SearchCol5").val('');
        $("#SearchModel_Value5").val('');
    }
    function ReadResponses(formid, pagenumber, sortOrder, sortField, reset ) {
       

        var SessioOrgId =' @Session["SelectedOrgId"]';

        //  alert("session: " + SessioOrgId +"  DropDown " + $("#dropdown-2").val());

        var OrgId = $("#dropdown-2").val();

        $.ajax({
            //url: '@Url.Action("ReadSortedResponseInfo","Home")' + '?formid=' + formid + "&page=" + pagenumber + "&sort=" + sortOrder + "&sortfield=" + sortField,
            url: '@Url.Action("ReadSortedResponseInfo","Home")' + '?formid=' + formid + '&page=' + pagenumber + '&sort=' + sortOrder + '&sortfield=' + sortField + '&orgid=' + OrgId + '&reset=' + reset
                + ReadSearchFields(),
            cache: false,
            type: 'GET',
            contentType: 'application/json; charset=utf-8',
            //data: JSON.stringify(model),
            success: successFunc
        });4

        //        $.ajaxSetup({ cache: false });

        function successFunc(data, status) {
            $('#right').html(data);
        }

        function errorFunc() {
            alert('error');
        }
    }
    function ReadResponse(ActionUrl) {
        ShowSppiner();
        var Url = window.location.pathname;
        var Formid = "";
        if (Url.indexOf("/") != -1) {
            Formid = Url.substring(Url.lastIndexOf("/") + 1);
            SetSettingButtonValue(Formid);
        }
        $.ajax({
            url: ActionUrl,
            type: 'GET',
            cache: false,
            contentType: 'application/json; charset=utf-8',
            //data: JSON.stringify(model),
            success: successFunc,
            Error: errorFunc
        });
        //		$.ajaxSetup({ cache: false });

        function successFunc(data, status) {

            $('#right').html(data);
            CloseSppiner();
        }

        function errorFunc() {
            CloseSppiner();
            alert('error');
        }

    }

    function GetSettings() {
        var ActionUrl = '@Url.Action("GetSettings","Home")' + '?formid=' + $("#FORM_ID_HIDDEN").val();
        ShowSppiner();
        $.ajax({
            url: ActionUrl,
            type: 'GET',
            cache: false,
            contentType: 'application/json; charset=utf-8',
            //data: JSON.stringify(model),
            success: successFunc,
            Error: errorFunc
        });
        //		 $.ajaxSetup({ cache: false });

        function successFunc(data, status) {
            $('#right').html(data);
            CloseSppiner();
        }

        function errorFunc() {
            alert('error');
            CloseSppiner();
        }

    }
    function SaveSettings() {
        ShowSppiner();
        var validation = true;
        $('.SelectedColumns').each(function () {

            if (this.length == 0) {
                validation = false;
            }
        });

        //if ($('select.SelectedColumns option').length > 0) {
        if (validation) {
            $('.SelectedColumns option').prop('selected', true);
            $('#SelectedUser option').prop('selected', true);
            $('#SelectedOrg option').prop('selected', true);

            var ActionUrl = '@Url.Action("SaveSettings","Home")' + '?formid=' + $("#FORM_ID_HIDDEN").val();
            var _form = $("#formsList").serialize();
            //alert(form);
            $.ajax({
                url: ActionUrl,
                type: 'POST',
                cache: false,
                //contentType: 'application/json; charset=utf-8',
                data: _form,
                dataType: "html",
                success: successFunc,
                Error: errorFunc
            });

        }
        else {
            CloseSppiner();
            alert('User should select at least one column for each form.');
            $('select.SelectedColumns option').focus();
        }


        //	$.ajaxSetup({ cache: false });

        function successFunc(data, status) {
            //  $('#right').html(data);
            //alert(data);
            if (data == "") {
                window.location.href = "Home";
            }
            else {
                $('#right').html(data);
            }

            $('#dropdown-1').focus();
            var FormId = $("#FORM_ID_HIDDEN").val();
            var FormMode = $("#FORM_MODE_HIDDEN").val();

            if (FormMode == "Final") {

                $('#' + FormId).removeClass("metro-staging");
                $('#' + FormId).addClass("metro-prod");
            }
            if (FormMode == "Draft") {
                $('#' + FormId).removeClass("metro-prod")
                $('#' + FormId).addClass("metro-staging");
            }
            CloseSppiner();
        }

        function errorFunc() {
            CloseSppiner();
            alert('error');
        }

        //    }
        // else
        //     {
        //         alert('User should select at least one column.');
        //         $('select#SelectedColumns option').focus();
        //    }
    }
    // Check For Concurrency
    function CheckForConcurrency(obj) {
        debugger;
        $("#ConcurrencyMessage").show();
        $(".dialogbtn").show();
        $("#NotifyMessage").hide();

        var ActionUrl = '@Url.Action("CheckForConcurrency", "Home")' + '?responseid=' + obj.id;
        $.ajax({
            url: ActionUrl,
            type: 'POST',
            cache: false,
            contentType: 'application/json; charset=utf-8',
            //data: JSON.stringify(model),
            success: successFunc,
            Error: errorFunc
        });

        //		 $.ajaxSetup({ cache: false });

        function successFunc(data, status) {
            var loggedInUserId = data.LoggedInUserId
            var UpdatedDate = data.DateUpdated;
            var SessionTimeOut = $('#SYSTEM_SESSION_TIMEOUT_HIDDEN').val() * 60000;
            UpdatedDate = UpdatedDate.replace(/[^0-9 +]/g, '');
            UpdatedDate = new Date(parseInt(UpdatedDate));
            var EditingDuration = Math.abs(new Date() - UpdatedDate);
            if (data.Status == 2 || data.Status == 4 || data.Status == 3) {
                $('#' + obj.id).closest("form").submit();
            }
            else
            {
                //alert("This recored is being edited.")
                // if time elapsed is less the   system timeout
               // alert("loggedInUserId " + loggedInUserId)
              //  alert("data.LastActiveUserId " + data.LastActiveUserId)
                if (EditingDuration <= SessionTimeOut && data.LastActiveUserId>0 && loggedInUserId != data.LastActiveUserId) {
                    alert("This record is being edited by another user.");
                }
                else {

                    if (loggedInUserId != data.LastActiveUserId) {
                        UnLockRecordForEdit(obj.id, false);
                    }
                    else
                    {
                        UnLockRecordForEdit(obj.id, true);

                    }

                }
                //$("#ConcurrencyDialog").data('ResponseId', obj.id)
                //$("#LastUpdated").val(UpdatedDate);
                //$("#EditingDuration").val(msToTime(EditingDuration));
                //$("#ConcurrencyDialog").dialog("open");
            }
        }

        function errorFunc() {
            alert('error');
        }


    }
    //CancelChange
    function CancelChange() {

        //		var ActionUrl = '@Url.Action("ReadSortedResponseInfo","Home")' + '?formid=' + $("#FORM_ID_HIDDEN").val();
        //		ReadResponse(ActionUrl);
        ReadResponses($("#FORM_ID_HIDDEN").val(), 1, '', '');
        $('#dropdown-1').focus();
    }
    function SetSettingButtonValue(formid) {
        $("#FORM_ID_HIDDEN").val(formid);

    }

    function SetSettingMode() {

        $("#FORM_MODE_HIDDEN").val($('#FormMode').find(":selected").text());

    }
    function UnLockRecordForDelete(ResponseId) {



        var ActionUrl = '@Url.Action("UnLock", "Home")' + '/' + ResponseId+'/False';
        
        $.ajax({
            url: ActionUrl,
            type: 'POST',
            cache: false,
            contentType: 'application/json; charset=utf-8',
            //data: JSON.stringify(model),
            success: successFunc1,
            Error: errorFunc1
        });
        function successFunc1(data, status)
        {
           
            if(data =="Success")
            {
                $("#exitdialog").data('ResponseId', ResponseId)
                $("#exitdialog").dialog("open");
            }
            else{
                
                alert('This record is being edited by another user.');              
            }
        }

        function errorFunc1() {
            
            alert('error');
        }
    }
    function UnLockRecordForEdit(ResponseId, RecoverLastRecordVersion) {



        var ActionUrl = '@Url.Action("UnLock", "Home")' + '?responseid=' + ResponseId + "&RecoverLastRecordVersion=" + RecoverLastRecordVersion;
        $.ajax({
            url: ActionUrl,
            type: 'POST',
            cache: false,
            contentType: 'application/json; charset=utf-8',
            //data: JSON.stringify(model),
            success: successFunc1,
            Error: errorFunc1
        });
        function successFunc1(data, status) {

            $('#' + ResponseId).closest("form").submit();
        }

        function errorFunc1() {
            alert('error');
        }
    }
    function ShowSppiner() {
        var validate = $('#formsList').validationEngine('validate');

        if (validate) {
            if (open) {
                $('BODY').jLoadingOverlay('close');
                open = false;
            }
            else {
                $('BODY').jLoadingOverlay('');
                open = true;
            }
        }
        $("#parent-selector :input").attr("disabled", true);
    }
    function CloseSppiner() {

        $('BODY').jLoadingOverlay('close');
        open = false;

        $("#parent-selector :input").attr("disabled", false);
    }

</script>
<script>
	$(document).ajaxStop(function () {

		var leftHeight = $("#left").height();
		var rightHeight = $("#right").height();
		if (leftHeight < rightHeight)
         {
             // $("#right").height(leftHeight)
             $("#left").height(rightHeight)
          }
		else 
        {
           // $("#left").height(rightHeight) 
        }
	});
	function msToTime(ms) {
	    
	    var hours = Math.floor(ms / 3600000); // 1 Hour = 36000 Milliseconds
	    var minutes = Math.floor((ms % 3600000) / 60000); // 1 Minutes = 60000 Milliseconds
	    var seconds = Math.floor(((ms % 360000) % 60000) / 1000); // 1 Second = 1000 Milliseconds

	    hours = (hours < 10) ? "0" + hours : hours;
	    minutes = (minutes < 10) ? "0" + minutes : minutes;
	    seconds = (seconds < 10) ? "0" + seconds : seconds;

	    return hours + ":" + minutes + ":" + seconds  ;
	}
</script>
<div id="pageHeader">
	<div id="pageTitle">
       
            <h2 style="margin:-3px 0px 0px 5px">
                Home
            </h2>
	</div>
 
	
	<div id="userwelcome">
		Welcome <strong>@Model.UserFirstName&nbsp;@Model.UserLastName </strong>&nbsp; | &nbsp;
	  @*  <a href="#">Log Out</a>*@
	 
     @if ( Model.UserHighestRole == 3)
      {
      @Html.ActionLink("Site Administration", "OrgList", "AdminOrganization", null, null);
    if (@System.Configuration.ConfigurationManager.AppSettings["WINDOW_AUTHENTICATION"].ToUpper() == "NO")
        {
       <span>&nbsp; | &nbsp;</span> 
    }
      }
      
      @if (Model.UserHighestRole == 2)
      {
      @Html.ActionLink("Site Administration", "UserList", "AdminUser", null, null);
    if (@System.Configuration.ConfigurationManager.AppSettings["WINDOW_AUTHENTICATION"].ToUpper() == "NO")
        {
       <span>&nbsp; | &nbsp;</span> 
    }
      }
      
@if (@System.Configuration.ConfigurationManager.AppSettings["IsDemoMode"] != null)
{
    if (@System.Configuration.ConfigurationManager.AppSettings["IsDemoMode"].ToUpper() == "TRUE")
    {
        <a href="http://www.cdc.gov/epiinfo/cloud/index.html">Log Out</a>

    }
    else
    {

        if (@System.Configuration.ConfigurationManager.AppSettings["WINDOW_AUTHENTICATION"].ToUpper() == "NO")
        {
            if (@System.Configuration.ConfigurationManager.AppSettings["WINDOW_AUTHENTICATION"].ToUpper() == "NO")
            {
                @Html.ActionLink("Log Out", "LogOut", "Home", null, null)
            }
        }

    }
}
	</div>
	<div style="clear: both;">
	</div>
</div>
<div id="content" style="@*margin-bottom: 200px;*@ padding-left: 10px; min-height: 375px; min-width:1200px; margin: 0 !important;">

	@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "formsList" }))
	{
		
	
		<div class="section group" id="main">
			<div id="left" class="col span_1_of_3" style="width: 317px !important; margin:0 !important;">
                <div id="leftarrangeby" style="float: left; vertical-align: middle; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 5px solid White; vertical-align: middle;">
		            <span class="css3-metro-dropdown">
			            <select id="dropdown-2" style="width: 172px;">
			               @* <option value="0" selected="selected" disabled="disabled">Arrange by:</option>*@
                           @foreach(var item in Model.OrganizationList){
				            <option value="@item.OrganizationId">@item.Organization</option>
                               }
				
				            @*	<option value="3">Last Saved Forms First</option>*@
			            </select>
		            </span>
                    <span class="css3-metro-dropdown">
			            <select id="dropdown-1" style="width: 131px;">
			               @* <option value="0" selected="selected" disabled="disabled">Arrange by:</option>*@
				            <option value="1">My Forms</option>
				            <option value="2">Forms Assigned to Me</option>
                            <option value="4">Forms Shared with Me</option>
				            <option value="3" selected="selected">All Forms</option>
				            @*	<option value="3">Last Saved Forms First</option>*@
			            </select>
		            </span>
	            </div>
				@Html.Partial("ListForms", Model.FormList)
                <div id="rightlegend" style="font-size: 9pt; vertical-align: baseline; color:#fff; margin-top: 15px;">
		            <div id="Div1" style="">
			            <img alt="" src="~/Content/images/designlegend1.png" align="middle" style="width: 16px;
				            vertical-align: middle;" />
			            My Forms</div>
		            <div id="Div2" style="">
			            <img alt="" src="~/Content/images/collectlegend1.png" align="middle" style="width: 16px;
				            vertical-align: middle;" />
			            Forms Assigned to Me</div>
                    <div id="Div6" style="">
                        <img alt="" src="~/Content/images/collectlegend2.png" align="middle" style="width: 16px;
				            vertical-align: middle;" />
                        Forms Shared with Me
                    </div>
                     
		            <div id="Div4" style="">
			            <img alt="" src="~/Content/images/prod1.png" align="middle" style="width: 16px;
				            vertical-align: middle;" />
			            Forms in Final</div>
		            <div id="Div3" style="">
			            <img alt="" src="~/Content/images/staging1.png" align="middle" style="width: 16px;
				            vertical-align: middle;" />
			            Forms in Draft</div>
	            </div>
			</div>
			<div id="right" class="col span_1_of_3" style="background: white; min-width: 800px; margin:10px !important;">
			   @* @Html.Partial("ListResponses", Model)*@
			</div>
		  <div style=""clear:both"></div>
		</div>
	}
	<div id="settingscontent" style="height:0;">
	   
	</div>
	<div id="exitdialog" title="Delete Record" >

			
			   <p style="font-size:1.20em; font-weight:600;">Are you sure you want to delete this record? </p>
				
			 
		   </div>
    <div id="ConcurrencyDialog" title="Record being Edited">

        <div id="ConcurrencyMessage">
            <p style="font-size:1.20em; font-weight:600;">This recored is being edited. Last time this record was updated is on: <input size="22" id="LastUpdated" type="text" readonly="readonly" /> </p>

            <p style="font-size:1.20em; font-weight:600;">Editing Duration (HH:MM:SS): <input size="22" id="EditingDuration" type="text" readonly="readonly" /> </p>
            <p style="font-size:1.20em; font-weight:600;">If the editing duration is considered too long please click the Notify button to Notify Form Owner.Otherwise try editing this record latter.</p>
            @*<p style="font-size:1.20em; font-weight:600;">otherwise try editing this record latter.  </p>*@
        </div>
        <div id="NotifyMessage" style="display: none;">

            <p style="font-size:1.20em; font-weight:600;"> An Email with appropriate  information have been sent to the form owner. </p>
        </div>
    </div>
</div>
 <div id="TimeOutdialog" title="Your session is about to expire!">
				<p>
					<span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>
					You will be logged off in <span id="dialog-countdown" style="font-weight:bold"></span>
				</p>

				<p>Do you want to continue your session?</p>
			 </div>
<input id="FORM_ID_HIDDEN" type="hidden" />
<input id="FORM_MODE_HIDDEN" type="hidden" />
<input id="FORM_SELECTED_HIDDEN" type="hidden" />
<input id="FORM_SEARCH_HIDDEN" type="hidden" />
<input id="FORM_SORTORDER_HIDDEN" type="hidden" />
<input id="FORM_SORTFIELD_HIDDEN" type="hidden" />
<input id="FORM_SelectedOrgId_HIDDEN" type="hidden" />
<input id="SYSTEM_SESSION_TIMEOUT_HIDDEN" type="hidden"  value="@Session.Timeout"/>


@*</div>  
  </div> *@ 
		 
